local wujian = fk.CreateSkill{
  name = "wk_heg__wujian",
}

Fk:loadTranslationTable{
  ["wk_heg__wujian"] = "忤谏",
  [":wk_heg__wujian"] = "若你手牌数为全场最多，你可以将手牌弃置至与一名全场手牌数最少的角色相同，视为使用【无懈可击】。",
}

wujian:addEffect("viewas",{
  pattern = "nullification",
  card_filter = function (self, player, to_select, selected, selected_targets)
    if not table.contains(player:getCardIds(Player.Hand), to_select) then return end
    if #selected == 0 then return true end
    local min_num = player:getHandcardNum()
    table.forEach(Fk:currentRoom().alive_players, function (p)
      if p:getHandcardNum() < min_num then
        min_num = p:getHandcardNum()
      end
    end)
    return #selected < player:getHandcardNum() - min_num
  end,
  view_as = function (self, player, cards)
    local min_num = player:getHandcardNum()
    table.forEach(Fk:currentRoom().alive_players, function (p)
      if p:getHandcardNum() < min_num then
        min_num = p:getHandcardNum()
      end
    end)
    if #cards == (player:getHandcardNum() - min_num) then
      local nullification = Fk:cloneCard("nullification")
      nullification:addFakeSubcards(cards)
      nullification.skillName = wujian.name
      return nullification
    end
  end,
  before_use = function (self, player, use)
    local room = player.room
    room:throwCard(use.card.fake_subcards, wujian.name, player)   
  end,
  enabled_at_response = function (self, player, response)
    local card_num = player:getHandcardNum()
    return not response and not player:isKongcheng() and table.every(Fk:currentRoom().alive_players, function (p)
      return card_num >= p:getHandcardNum()
    end) and table.find(Fk:currentRoom().alive_players, function (p)
      return card_num > p:getHandcardNum()
    end)
  end
})

return wujian